//chatuser.redux

import axios from 'axios';

//定义动作类型
const USER_LIST = 'USER_LIST';

//用户初始状态
const initState = {
	userList:[]
}

//reducer
export function chatuser(state = initState,action){
	switch (action.type){
		case USER_LIST:
			return {...state,userList:action.payload}
		default:
			return state;
	}
}

function getUserListSuccess(data){
	return{type:USER_LIST,payload:data};

}


//进行的动作
export function getUserList(type){
	return dispatch =>{
		
		axios.get('/user/list?type='+type)
			.then(res =>{
				if (res.status === 200) {
					if (res.data.code === 0) {
						dispatch(getUserListSuccess(res.data.content));
					} else{
						console.log(res.data.msg);
					}
				} else{
					console.log('服务器响应失败');
				}
			});
		
	} 
}
